package com.totoro.springboot.druid.controller;

import com.totoro.springboot.druid.model.User;
import com.totoro.springboot.druid.service.IUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by Niki on 2018/2/7 8:57
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    IUserService userService;

    @GetMapping("/all")
    public Object findUsers() {
        return userService.findAll();
    }

    @PostMapping("/add/{name}/{age}")
    public Long addUser(@PathVariable String name, @PathVariable Integer age) {
        User user = new User(name, age);
        return userService.addUser(user);
    }

    @PutMapping("/update/{id}/{name}/{age}")
    public boolean updateUser(@PathVariable Long id, @PathVariable String name, @PathVariable Integer age) {
        User user = new User(name, age);
        user.setId(id);
        userService.updateUser(user);
        return true;
    }
}
